package com.jyxd.web.controller.czform;

import com.jyxd.web.data.czform.CRRTNurse;
import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.data.user.User;
import com.jyxd.web.service.czform.CRRTNurseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

import static com.jyxd.web.service.czform.CRRTNurseService.CRRT_NURSE_TYPE_THREE;
import static com.jyxd.web.service.czform.CRRTNurseService.CRRT_NURSE_TYPE_TWO;
import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Api(tags = "crrt护理表单信息")
@Controller
@RequestMapping(value = "/crrtNurse")
public class CRRTNurseController {

    @Autowired
    private CRRTNurseService crrtNurseService;

    @ApiOperation("增加一条CRRT表单二记录")
    @RequestMapping(value = "/insertTwo", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult saveOrUpdateCRRTNurseTwo(@RequestBody CRRTNurse crrtNurse, HttpSession session) {
        errorIfEmpty(crrtNurse, "表单内容不能为空");
        if (crrtNurse.getSignature()==null){
            User user = (User) session.getAttribute("user");
            crrtNurse.setSignature(user.getUserName());
        }
        return crrtNurseService.saveOrUpdateCRRTNurse(crrtNurse);
    }

    @ApiOperation("增加一条CRRT表单三记录")
    @RequestMapping(value = "/insertThree", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult saveOrUpdateCRRTNurseThree(@RequestBody CRRTNurse crrtNurse) {
        return crrtNurseService.saveOrUpdateCRRTNurse(crrtNurse);
    }

    @ApiOperation("根据条件分页查询CRRT二表单列表（也可以不分页）")
    @RequestMapping(value = "/queryTwoList", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult queryTwoList(@RequestBody Map<String, Object> map) {
        errorIfEmpty(map, "表单内容不能为空");
        map.put("type", CRRT_NURSE_TYPE_TWO);
        return crrtNurseService.queryList(map);
    }

    @ApiOperation("根据条件分页查询CRRT三表单列表（也可以不分页）")
    @RequestMapping(value = "/queryThreeList", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult queryThreeList(@RequestBody Map<String, Object> map) {
        errorIfEmpty(map, "表单内容不能为空");
        map.put("type", CRRT_NURSE_TYPE_THREE);
        return crrtNurseService.queryList(map);
    }

    @ApiOperation("根据id删除一条表单")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult deleteData(@RequestBody Map<String, Object> map) {
        errorIfEmpty(map, "表单内容不能为空");
        String id = (String) map.get("id");
        return crrtNurseService.deleteData(id);
    }

    @ApiOperation("获取CRRT顺延数据")
    @RequestMapping(value = "/copyData", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult copyData (@RequestBody Map<String, Object> map) {
        return crrtNurseService.copyData(map);
    }

    @ApiOperation("根据条件分页查询CRRT二表单列表（也可以不分页）")
    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult queryList(@RequestBody Map<String, Object> map) {
        errorIfEmpty(map, "表单内容不能为空");
        return crrtNurseService.queryListV2(map);
    }
}
